import pandas as pd

from GenericExcel import GenericExcel


class AsmExcel(GenericExcel):
    STATION_NO = '区站号(字符)'
    LATITUDE = '纬度'
    LONGITUDE = '经度'
    HEIGHT = '测站高度'
    CITY = '地市名'
    STATION_NAME = '站名'
    COUNTY = '区县名'
    TIMESTAMP = '入库时间'
    # 土壤体积含水量 (Volumetric Water Content, VWC)
    VWC = 'VWC'
    # 土壤相对湿度 (Soil Relative Humidity, SRH)
    SRH = 'SRH'
    # 土壤重量含水率 (Gravimetric Water Content, GWC)
    GWC = 'GWC'
    # 土壤有效水分贮存量 (Available Water Storage, AWS)
    AWS = 'AWS'

    def __init__(self, file_path):
        GenericExcel.__init__(self, file_path)
        pass

    def append_col_timestr(self, time_pattern, col_name='__timestr__'):
        df = self.df
        # 将时间列转换为日期时间格式
        df[col_name] = pd.to_datetime(df[AsmExcel.TIMESTAMP])
        # 按小时转换成统一格式
        df[col_name] = df[col_name].dt.strftime(time_pattern)
        # 获取不重复的列表
        return df[col_name].unique().tolist()
